CROSSTOOLDIR		:=/home/public/au/gateway/release/SDK/openwrt-sdk-ramips-mt76x8_gcc-7.3.0_musl.Linux-x86_64
CROSS   		:= mipsel-openwrt-linux-
export  STAGING_DIR	:= $(CROSSTOOLDIR)/staging_dir
export  PATH		:= $(PATH):$(STAGING_DIR)/toolchain-mipsel_24kc_gcc-7.3.0_musl/bin
CROSS_CFLAGS		:= -I$(CROSSTOOLDIR)/staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/usr/include
CROSS_CFLAGS		+= -I$(CROSSTOOLDIR)/staging_dir/target-mipsel_24kc_musl/usr/include
CROSS_LDFLAGS		:= -L$(CROSSTOOLDIR)/staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_musl/usr/lib
CROSS_LDFLAGS		+= -L$(CROSSTOOLDIR)/staging_dir/target-mipsel_24kc_musl/usr/lib

TARGET_CFLAGS		:= 	-fno-stack-protector

ROOTDIR=$(shell pwd)
BUILDDIR=$(ROOTDIR)/build

INC=-I./common 
INC +=-I./ble 
INC +=-I./ble/inc

DIRS=./common 
DIRS += ./ble 
DIRS += ./ble/src 

#这里递归遍历3级子目录
#DIRS := $(shell find . -maxdepth 3 -type d)
CSRCS 			:= $(foreach dir,$(DIRS),$(wildcard $(dir)/*.c))
CPPSRCS 			:= $(foreach dir,$(DIRS),$(wildcard $(dir)/*.cpp))

OBJS			:= $(patsubst %.c, %.o, $(CSRCS))
CPPOBJS			:= $(patsubst %.cpp, %.o, $(CPPSRCS))

LIBS := -lm -lrt -ldl -lpthread	-lstdc++
LIBS += -lmosquitto -lssl -lcrypto -ljson-c  -lxml2 -lz -ljansson -lubox -lblobmsg_json -lubus -lcares  -llua -luci -lcurl -lmbedx509 -lmbedcrypto -lmbedtls -luuid 

CC 			:=  	$(CROSS)gcc
CPP 			:=  	$(CROSS)g++
STRIP                   := $(CROSS)strip


ALL: $(OBJS)$(CPPOBJS) 
	$(CC) main.c $(OBJS) $(CPPOBJS)  $(INC) $(CROSS_CFLAGS) $(LIBS) $(CROSS_LDFLAGS) -o bletest

%.o:%.c
	$(CC) $(CFLAGS) $(LIBS) $(INC)  $(CROSS_CFLAGS) -o $@ -c $^
%.o:%.cpp
	$(CPP) $(CFLAGS) $(LIBS) $(INC) $(CROSS_CFLAGS)  -o $@ -c $^

clean:
	rm bletest
	rm ./common/*.o 
	rm  ./ble/*.o 
	rm  ./ble/src/*.o 

strip:
	$(STRIP) bletest